package edu.ccut.saturn.component.impl.sql;

import java.util.List;
import java.util.Map;

import edu.ccut.saturn.component.SaturnComponentException;

public class IsNotEmptyItemInfo extends AbstractSingleExprSqlItemInfo {

	public IsNotEmptyItemInfo(String prepend, String property) {
		super(prepend, property);
	}

	@SuppressWarnings("unchecked")
	@Override
	public String getSubSql(Map<String, Object> param) throws Exception {

		if (this.getProperty() != null && param.get(this.getProperty()) != null) {

			if (param.get(this.getProperty()) instanceof List) {

				if (((List) param.get(this.getProperty())).size() > 0) {
					return parseSql(param);

				} else {
					return " ";
				}
			}

			if (param.get(this.getProperty()) instanceof Map) {

				if (((Map) param.get(this.getProperty())).size() > 0) {
					return parseSql(param);

				} else {
					return " ";
				}
			}

			if (!"".equals(param.get(this.getProperty()))) {

				return parseSql(param);

			} else {
				return " ";
			}
		}
		throw new SaturnComponentException("");
	}

	@Override
	public String getType() {
		return "isNotEmpty";
	}
}
